package com.gao.security.verificationcode.storage;


import com.gao.security.verificationcode.base.BaseCode;
import com.gao.security.verificationcode.base.BaseCodeOperationManager;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * <p>
 *    内存操作验证码--默认方式
 * </p>
 *
 * @author GaoShuangWen
 */
@Component
@Slf4j
public class InMemoryCodeOperationManager implements BaseCodeOperationManager {
    private Map<String,BaseCode> map=Maps.newHashMap();

    @Override
    public boolean saveCode(BaseCode baseCode) {
        log.info("验证码：【{}】，key：【{}】",baseCode.getCode(),baseCode.getUuid());
        map.put(baseCode.getUuid(),baseCode);
        return true;
    }

    @Override
    public BaseCode getCodeObject(String key) {
        return map.get(key);
    }


    @Override
    public boolean remove(String key) {
        map.remove(key);
        return true;
    }
}
